package com.example.a22310.myapplication.ViewModel.User;


import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.example.a22310.myapplication.Beans.UserInfo;
import com.example.a22310.myapplication.Listener.ClubListener;
import com.example.a22310.myapplication.Model.UserModel;

import static com.example.a22310.myapplication.GloableClass.Yuejian.IMG_URL;

public class GetUserInformationViewModel implements ClubListener<UserInfo> {
    private ActivityUserInformationBinding binding;
    private AppCompatActivity activity;
    private int userid;


    public GetUserInformationViewModel(AppCompatActivity activity, ActivityUserInformationBinding binding,int userid){
        this.activity = activity;
        this.binding = binding;
        this.userid = userid;
        binding.setGetuserinfo(this);
        UserModel userModel=new UserModel();
        userModel.userInfo(GetUserInformationViewModel.this,userid);

    }


    @Override
    public void setContentView() {

    }

    @Override
    public void initView() {

    }

    @Override
    public void initEvent() {

    }

    @Override
    public void setTitle() {

    }

    @Override
    public void onBackPressed() {

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return false;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return false;
    }

    @Override
    public void onSuccess(UserInfo userInfo) {

        binding.name.setText(userInfo.getUser_name());
        binding.address.setText(userInfo.getAddress());
        if (userInfo.getUser_picture()!=null){
            Picasso.with(activity).load(IMG_URL+userInfo.getUser_picture()).into(binding.usrImg);
        }

    }

    @Override
    public void onFailure() {
        Toast.makeText(activity,"连接服务器失败",Toast.LENGTH_LONG).show();
    }
}